/* Blink out Morse Code 

Arduino 0021 with Teensyduino
Teensy 2.0 w/ pins

As is this program blinks out every letter of the alphabet
with the default LED on Pin 11

Future revisions will take input from a pin or via 
usb and blink the morse code iteration of the input


*/ 

#include <stdio.h>
#include <string.h>
#define ALPHABET_SIZE 26 //used for alphabet array size
#define OUTPIN 11
#define DELAYTIME 1000

struct letter
{
	char let; //ascii letter
	char code[6];//morse code desc
}; 

void setup() 
{
   pinMode(OUTPIN,OUTPUT);   
}

/* Define the alphabet */ 
struct letter alphabet[ALPHABET_SIZE] = { {'A',".-"},{'B',"-.."},
                                          {'C',"-.-."},{'D',"-.."}, 
                                          {'E',"."},{'F',"..-."}, 
                                          {'G',"--."},{'H',"...."},
                                          {'I',"..."},{'J',".---"},
                                          {'K',"-.-"},{'L',".-.."},
                                          {'M',"--"},{'N',"-."},
                                          {'O',"---"},{'P',".--."},
                                          {'Q',"--.-"},{'R',".-."},
                                          {'S',"..."},{'T',"-"},
                                          {'U',"..-"},{'V',"...-"},
                                          {'W',".--"},{'X',"-..-"},
                                          {'Y',"-.--"},{'Z',"--.."}};
 
void loop()
{
	int i;
	for(i=0;i<ALPHABET_SIZE;i++)//foreach letter
        {
            delay(5000); //delay between letters 5 seconds
            
            int j;
            for(j=0;j<6;j++)//foreach morse code bit in the letter
            {
               delay(500); //delay between signals
               
               if(alphabet[i].code[j] == '.')
               {
                   digitalWrite(OUTPIN,HIGH);
                   delay(DELAYTIME);
                   digitalWrite(OUTPIN,LOW);
                   
               }
               else if(alphabet[i].code[j] == '-')
               {
                 digitalWrite(OUTPIN,HIGH);
                 delay(DELAYTIME*3); // one - is = 3 . 
                 digitalWrite(OUTPIN,LOW);
               }
               else
                 break;
               
            }
            
        }
	    
}



